package com.atguigu.spzx.order.controller;

import com.atguigu.spzx.model.dto.order.OrderSubmitDto;
import com.atguigu.spzx.model.entity.order.OrderInfo;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.order.OrderTradeVo;
import com.atguigu.spzx.order.service.OrderInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "订单模块")
@RequestMapping("/api/order/orderInfo")
public class OrderInfoController {
    @Resource
    OrderInfoService orderInfoService;
    @Operation(summary = "更新订单支付状态接口")
    @PutMapping("/auth/updateOrderPayStatus/{orderNo}")
    public Result updateOrderPayStatus(@PathVariable("orderNo") String orderNo){
        orderInfoService.updateOrderPayStatus(orderNo);
        return Result.ok();
    }
    @Operation(summary = "根据订单编号查询订单详情接口")
    @GetMapping("/auth/findOrderByOrderNo/{orderNo}")
    public Result findOrderByOrderNo(@PathVariable("orderNo")Long orderNo){
        OrderInfo orderInfo = orderInfoService.findOrderByOrderNo(orderNo);
        return Result.ok().data(orderInfo);
    }

    @Operation(summary = "查询订单分页数据")
    @GetMapping("/auth/{page}/{limit}")
    public Result page(@PathVariable("page")Integer page,
                       @PathVariable("limit")Integer limit,
                       Integer orderStatus){
        PageInfo<OrderInfo> pageInfo = orderInfoService.page(page,limit,orderStatus);
        return Result.ok().data(pageInfo);
    }


    //在商品详情页点击立即购买 跳转到订单确认页
    @Operation(summary = "立即购买接口")
    @GetMapping("/auth/buy/{skuId}")
    public Result buy(@PathVariable("skuId")Long skuId){
        OrderTradeVo vo = orderInfoService.buy(skuId);
        return Result.ok().data(vo);
    }
    @Operation(summary = "查询订单详情接口")
    @GetMapping("/auth/{id}")
    public Result getOrderDetail(@PathVariable("id")Long id){
        OrderInfo orderInfo = orderInfoService.findOrderById(id);
        return Result.ok().data(orderInfo);
    }
    @Operation(summary = "提交订单接口")
    @PostMapping("/auth/submitOrder")
    public Result submitOrder(@RequestBody OrderSubmitDto orderSubmitDto){
        Long orderId = orderInfoService.submitOrder(orderSubmitDto);
        return Result.ok().data(orderId);
    }
    @Operation(summary = "结算接口")
    @GetMapping("/auth/trade")
    public Result trade(){
        OrderTradeVo orderTradeVo = orderInfoService.trade();
        return Result.ok().data(orderTradeVo);
    }
}
